const jwt = require('jsonwebtoken');

function generateToken (data, privateKey, expire) {
    return Buffer.from(jwt.sign(data, privateKey, { expiresIn: expire })).toString('base64');
}

function parseToken (data, privateKey) {
    let buff = Buffer.from(data, 'base64');
    return jwt.verify(buff.toString(), privateKey);
}

module.exports = {
    generateToken,
    parseToken
};
